//
//  CDCommentViewCell.m
//  CuriosityDaily3
//
//  Created by panzhi on 16/9/23.
//  Copyright © 2016年 theBestTeam. All rights reserved.
//

#import "CDCommentViewCell.h"
#import "CDCustomButton.h"

@interface CDCommentViewCell ()
@property(nonatomic,weak)UIImageView *imageview;
@property(nonatomic,weak)UILabel *namelabel;
@property(nonatomic,weak)UILabel *updatetime;
@property(nonatomic,weak)UIImageView *lineview;
@property(nonatomic,weak)UILabel *contentalabel;
@property(nonatomic,weak)UILabel *myCommentlabel;
@property(nonatomic,weak)UIButton *responseBtn;
@property(nonatomic,weak)UIImageView *bottomMarginview;


/**
 *  [self.contentView addSubview:imageview];
 [self.contentView addSubview: namelabel];
 [self.contentView addSubview:updateTime];
 [self.contentView addSubview:lineview];
 [self.contentView addSubview: contentalabel];
 [self.contentView addSubview: myCommentlabel];
 [self.contentView addSubview: responseBtn];
 */
@end

@implementation CDCommentViewCell

- (void)awakeFromNib {

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}

//- (instancetype)initWithFrame:(CGRect)frame
//{
//    self = [super initWithFrame:frame];
//    if (self) {
//        [self setupUI];
//    }
//    return self;
//}

-(void)setupUI{
    
    UIImageView *imageview = [[UIImageView alloc]init];
    imageview.image = [UIImage imageNamed:@"Home@iPadPro_Yellow"];
    imageview.backgroundColor = [UIColor randomColor];
    
    
    UILabel *namelabel = [[UILabel alloc]init];
    namelabel.text = @"namelabel";
    [namelabel setFont:[UIFont systemFontOfSize:12]];
    [namelabel sizeToFit];
    
    UILabel *updateTime = [[UILabel alloc]init];
    updateTime.text = @"一小时前评论了你";
    [updateTime setFont:[UIFont systemFontOfSize:12]];
    [updateTime sizeToFit];
    updateTime.textColor = [UIColor colorWithHex:0xd2d2d2];
    
    UILabel *contentalabel = [[UILabel alloc]init];
    contentalabel.text = @"你好";
    [contentalabel setFont:[UIFont systemFontOfSize:12]];
    [contentalabel sizeToFit];
    contentalabel.numberOfLines = 0;
    
    
    UIImageView *lineview = [[UIImageView alloc]init];
    lineview.backgroundColor = [UIColor darkGrayColor];
    lineview.backgroundColor = [UIColor colorWithHex:0xd2d2d2];
    
    UILabel *myCommentlabel = [[UILabel alloc]init];
    myCommentlabel.text = @"评论内容";
    [myCommentlabel setFont:[UIFont systemFontOfSize:12]];
    [myCommentlabel sizeToFit];
    myCommentlabel.numberOfLines = 0;
        myCommentlabel.textColor = [UIColor colorWithHex:0xd2d2d2];
    
    CDCustomButton *responseBtn = [[CDCustomButton alloc]init];
    [responseBtn setTitle:@"回复" forState:UIControlStateNormal];
    [responseBtn setTitleColor:[UIColor colorWithHex:0xffcd34] forState:UIControlStateNormal];
    [responseBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
    [responseBtn sizeToFit];
    
    UIImageView *bottomMarginview = [[UIImageView alloc]init];
    bottomMarginview.backgroundColor = [UIColor colorWithHex:0xd2d2d2];
    [self.contentView addSubview:bottomMarginview];
    
    self.imageview = imageview;
    self.namelabel = namelabel;
    self.updatetime = updateTime;
    self.lineview = lineview;
    self.contentalabel = contentalabel;
    self.myCommentlabel = myCommentlabel;
    self.responseBtn = responseBtn;
    self.bottomMarginview = bottomMarginview;
    
    
    [self.contentView addSubview:imageview];
    [self.contentView addSubview:namelabel];
    [self.contentView addSubview:updateTime];
    [self.contentView addSubview:lineview];
    [self.contentView addSubview:contentalabel];
    [self.contentView addSubview:myCommentlabel];
    [self.contentView addSubview:responseBtn];
    
    [self.bottomMarginview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(0);
        make.left.right.equalTo(self.contentView);
        make.height.offset(5);

    }];
    
    [self.imageview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomMarginview.mas_bottom).offset(10);
        make.left.offset(10);
        make.width.height.offset(35);
    }];
    
    [self.namelabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageview.mas_top).offset(2);
        make.left.equalTo(self.imageview.mas_right).offset(8);
        make.width.offset(200);
    }];
    
    [self.updatetime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.namelabel.mas_bottom).offset(4);
        make.left.equalTo(self.namelabel.mas_left);
        make.width.equalTo(self.namelabel);
    }];
    
    [self.contentalabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageview.mas_bottom).offset(8);
        make.left.equalTo(self.imageview.mas_left);
        make.width.offset(300);
    }];
    
    [self.lineview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentalabel.mas_bottom).offset(10);
        make.centerX.equalTo(self.contentView);
        make.width.equalTo(self.contentView.mas_width).offset(-20);
        make.height.offset(1/[UIScreen mainScreen].scale);
    }];
    
    [self.myCommentlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineview.mas_bottom).offset(10);
        make.left.equalTo(self.imageview);
        make.width.offset(300);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
    }];
    
    [self.responseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.namelabel);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.width.offset(50);
        make.height.offset(30);
    }];
    
    
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.imageview.layer.cornerRadius = self.imageview.frame.size.width * 0.5;
    self.imageview.layer.masksToBounds = YES;

    self.responseBtn.layer.cornerRadius = self.imageview.frame.size.width / 3;
    self.responseBtn.layer.masksToBounds = YES;
    
}

-(void)drawRect:(CGRect)rect{



}

@end
